import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import store from "@/store";
export interface ResponseProps {
    code: number;
    data: any;
    msg: string;
}
export const axiosInstance = axios.create({
    baseURL: "/",
    timeout: 1000 * 60,
});
axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {
    store.commit("setError", { status: false, message: "" });
    store.commit("setLoading", true);
    return config;
});
axiosInstance.interceptors.response.use(
    (response: AxiosResponse) => {
        store.commit("setLoading", false);
        return response.data;
    },
    err => {
        const { error } = err.response.data;
        store.commit("setError", { status: true, message: error });
        store.commit("setLoading", false);
        return Promise.reject(error);
    }
); 
export default (requestConfig: AxiosRequestConfig): Promise<ResponseProps> => axiosInstance.request(requestConfig);
